package com.ATMgui;

import com.lovo.util.Util;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Menu extends JPanel implements ActionListener {
    private Icon quqian = Util.getIcon("/image/buttonGet.jpg");

    private Icon cunkuan = Util.getIcon("/image/buttonSave.jpg");
    private Icon chaxun = Util.getIcon("/image/buttonFind.jpg");
    private Icon exit = Util.getIcon("/image/buttonOff.jpg");
    private Icon AlterImg = Util.getIcon("/image/buttonModify.jpg");
    private ATM frame;
    private JButton tuichu;
    private JButton quqianBtn;
    private JButton cunkuanBtn;
    private JButton chaxunBtn;
    private JButton AlterBtn;
    private JButton zhuanzhang;

    public Menu(ATM frame) {
        this.frame = frame;
        this.setLayout(null);

        this.setOpaque(false);
        quqianBtn = new JButton(quqian);
        quqianBtn.setBounds(0, 110, 100, 20);
        this.add(quqianBtn);
        quqianBtn.addActionListener(this);

        this.setOpaque(false);
        cunkuanBtn = new JButton(cunkuan);
        cunkuanBtn.setBounds(0, 220, 100, 20);
        this.add(cunkuanBtn);
        cunkuanBtn.addActionListener(this);

        this.setOpaque(false);
        chaxunBtn = new JButton(chaxun);
        chaxunBtn.setBounds(0, 340, 100, 20);
        this.add(chaxunBtn);
        chaxunBtn.addActionListener(this);

        this.setOpaque(false);
        tuichu = new JButton(exit);
        tuichu.setBounds(700, 110, 100, 20);
        this.add(tuichu);
        tuichu.addActionListener(this);

        this.setOpaque(false);
        AlterBtn = new JButton(AlterImg);
        AlterBtn.setBounds(700, 220, 100, 20);
        this.add(AlterBtn);
        AlterBtn.addActionListener(this);

        this.setOpaque(false);
        zhuanzhang = new JButton("转账");
        zhuanzhang.setBounds(700, 340, 100, 20);
        this.add(zhuanzhang);
        zhuanzhang.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == tuichu) {
            frame.switchPanel("登陆");
        } else if (e.getSource() == chaxunBtn) {
            String str = "";
            str = frame.getUsersList().get(frame.getNum()).getBlance() + "";
            frame.getFindMoney().getTextField1().setText(str);
            frame.switchPanel("查询");
        } else if (e.getSource() == quqianBtn) {
            frame.switchPanel("取钱");
        } else if (e.getSource() == cunkuanBtn) {
            frame.switchPanel("存钱");
        } else if (e.getSource() == AlterBtn) {
            frame.switchPanel("改密码");
        } else if (e.getSource() == zhuanzhang) {
            frame.switchPanel("转账");
        }
    }
}
